Total Complexity | 8 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | import toJson from './toJson.js'; |
||
3 | class Diff { |
||
4 | constructor(currentArray, otherArray, total) { |
||
5 | 4 | this.currentArray = currentArray; |
|
6 | 4 | this.otherArray = otherArray; |
|
7 | 4 | this.total = total; |
|
8 | } |
||
9 | |||
10 | get differenceArray() { |
||
11 | 4 | const otherArray = toJson(this.otherArray); |
|
12 | 4 | return this.currentArray.filter( |
|
13 | 12 | (value) => !otherArray.includes(JSON.stringify(value)) |
|
14 | ); |
||
15 | } |
||
16 | |||
17 | get differenceArrayB() { |
||
18 | 4 | if (!this.total) { |
|
19 | 2 | return []; |
|
20 | } |
||
21 | 2 | const currentArray = toJson(this.currentArray); |
|
22 | |||
23 | 2 | return this.otherArray.filter( |
|
24 | 6 | (value) => !currentArray.includes(JSON.stringify(value)) |
|
25 | ); |
||
26 | } |
||
27 | |||
28 | get compare() { |
||
29 | 4 | return this.differenceArray.concat(this.differenceArrayB); |
|
30 | } |
||
31 | |||
32 | static create(currentArray, otherArray, total) { |
||
33 | 4 | const differ = new Diff(currentArray, otherArray, total); |
|
34 | |||
35 | 4 | return differ.compare; |
|
36 | } |
||
37 | } |
||
38 | |||
42 |